package TestModel;

import java.util.LinkedList;
import DataModel.CommonLibrary.CommonDefs;
import DataModel.LayoutManager.CEdge;
import DataModel.LayoutManager.CRectangle;
import ScanLineAlghorithms.RectanglesUnion.RectanglesUnion;
import junit.framework.TestCase;

public class UnionTest extends TestCase {
	CRectangle u1;
	CRectangle u2;
	CRectangle u3;
	CRectangle u4;
	CRectangle u5;
	
	CEdge vc1; 
	CEdge vc2; 
	CEdge vc3; 
	CEdge vc4; 
	CEdge vc5; 
	CEdge vc6;
	CEdge vc7;
	CEdge vc8;
	CEdge vc9; 
	CEdge vc10;
	CEdge vc11;
	CEdge vc12;
	
	CEdge hc1; 
	CEdge hc2; 
	CEdge hc3; 
	CEdge hc4; 
	CEdge hc5; 
	CEdge hc6;
	CEdge hc7;
	CEdge hc8;
	CEdge hc9; 
	CEdge hc10;
	CEdge hc11;
	CEdge hc12;
	
	
	LinkedList<CRectangle> urecs;
	
	
	
	
	LinkedList<CEdge> result;
	LinkedList<CEdge> resultC;
	
	
	public void setUp() {
		u1 = new CRectangle(1,2,3,6,CommonDefs.Layer.Metal1,1);
		u2 = new CRectangle(2,5,7,7,CommonDefs.Layer.Metal1,2);
		u3 = new CRectangle(2,0,7,3,CommonDefs.Layer.Metal1,3);
		u4 = new CRectangle(6,2,10,6,CommonDefs.Layer.Metal1,4);
		u5 = new CRectangle(1,7,10,9,CommonDefs.Layer.Metal1,5);
		urecs =  new LinkedList<CRectangle>();
		urecs.add(u1);
		urecs.add(u2);
		urecs.add(u3);
		urecs.add(u4);
		urecs.add(u5);
		
		
		vc1 =  new CEdge(1,2,1,6,1,null);
		vc2 =  new CEdge(2,0,2,2,2,null);
		vc3 =  new CEdge(1,7,1,9,3,null);
		vc4 =  new CEdge(3,5,3,3,4,null);
		vc5 =  new CEdge(6,3,6,5,5,null);
		vc6 =  new CEdge(7,2,7,0,6,null);
		vc7 =  new CEdge(10,9,10,7,7,null);
		vc8 =  new CEdge(10,6,10,2,8,null);
		vc9 =  new CEdge(2,6,2,7,8,null);
		vc10 =  new CEdge(7,7,7,6,8,null);
		vc11=  new CEdge(3,5,3,3,8,null);
		vc12 =  new CEdge(6,3,6,5,8,null);
		
		
		
		hc1 =  new CEdge(7,0,2,0,1,null);
		hc2 =  new CEdge(2,2,1,2,2,null);
		hc3 =  new CEdge(10,2,7,2,3,null);
		hc4 =  new CEdge(3,3,6,3,4,null);
		hc5 =  new CEdge(6,5,3,5,5,null);
		hc6 =  new CEdge(1,6,2,6,6,null);
		hc7 =  new CEdge(7,6,10,6,7,null);
		hc8 =  new CEdge(1,9,10,9,8,null);
		hc9 =  new CEdge(2,7,1,7,8,null);
		hc10 =  new CEdge(10,7,7,7,8,null);
		hc11=  new CEdge(3,3,6,3,8,null);
		hc12 =  new CEdge(6,5,3,5,8,null);

		
		resultC = new LinkedList<CEdge>();
		resultC.add(vc1);
		resultC.add(hc6);
		resultC.add(vc9);
		resultC.add(hc9);
		resultC.add(vc3);
		resultC.add(hc8);
		resultC.add(vc7);
		resultC.add(hc10);
		resultC.add(vc10);
		resultC.add(hc7);
		resultC.add(vc8);
		resultC.add(hc3);
		resultC.add(vc6);
		resultC.add(hc1);
		resultC.add(vc2);
		resultC.add(hc2);
		resultC.add(vc11);
		resultC.add(hc11);
		resultC.add(vc12);
		resultC.add(hc12);
		
		
		
		
		
		
		
		
		
		
		
		
		
		
	}
	public void testUnion() {
		setUp();
		result = RectanglesUnion.Activate(urecs);
		for(int i = 0; i<resultC.size();i++) {
			CEdge e1 = resultC.get(i);
			CEdge e2 = result.get(i);
			assertTrue("Result Edge: expected  ["+e1.ToString()+"] , got: ["+e2.ToString()+"]",CEdge.CompareCoords(e1, e2));
		}
		printResult();
		
	}
	@SuppressWarnings("unchecked")
	public void printResult() {
		
		System.out.println("result");
		System.out.println("...........");
		for (CEdge e :result) {
			CEdge.printEdge(e);
		}
		
	}
	
	

}
